package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.kpi.KpiDto;
import com.cxx.home.service.KpiService;
import com.cxx.home.vo.KpiQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kpi")
@Tag(name = "绩效")
public class KpiController {
    @Resource
    private KpiService kpiService;

    @Operation(summary = "查询绩效")
    @GetMapping("")
    public @JsonView(ReadView.class) List<KpiDto> queryKpi(KpiQueryVo queryVo) {
        return kpiService.queryKpi(queryVo);
    }

    @Operation(summary = "新增绩效")
    @PostMapping("")
    public Boolean addKpi(@RequestBody @JsonView(WriteView.class) @Validated KpiDto kpiDto) {
        return kpiService.addKpi(kpiDto);
    }

    @Operation(summary = "更新绩效")
    @PutMapping("/{id}")
    public Boolean updateKpi(@PathVariable("id") long id,
                             @RequestBody @JsonView(WriteView.class) KpiDto kpiDto) {
        return kpiService.updateKpi(id, kpiDto);
    }

    @Operation(summary = "删除绩效")
    @DeleteMapping("/{id}")
    public Boolean deleteKpi(@PathVariable("id") long id) {
        return kpiService.deleteKpi(id);
    }
}
    